package biznussoft.metercor.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import biznussoft.metercor.MainActivity;
import biznussoft.metercor.R;
import biznussoft.metercor.entity.ActivityModel;
import biznussoft.metercor.utils.Session;

import com.salesforce.androidsdk.rest.RestClient;

public class ServiceOrderActionMenus extends Fragment implements OnClickListener {
	private RestClient client;
	private ActivityModel mobel;
	private String sId;
	int position;
	private ImageView time,material,expenses,newTime,newMaterial,newExpenses;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.service_menus, null);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		time = (ImageView) getView().findViewById(R.id.time);
		material = (ImageView) getView().findViewById(R.id.material);
		expenses = (ImageView) getView().findViewById(R.id.expenses);
		client =  MainActivity.mActivity.client;
		time.setOnClickListener(this);
		material.setOnClickListener(this);
		expenses.setOnClickListener(this);

		Bundle i = getArguments();
		position = i.getInt("Position");

		mobel = ServiceOrderActivityRecordsFragment.list.get(position);
		Session.sFconnectActivity =mobel.getActivityName();
		sId = mobel.getId();

		time.setImageResource(R.drawable.time_active);

		TimeMasterFragment newFragment1 = new TimeMasterFragment();
		Bundle args = new Bundle();
		args.putInt("Position", position);
		newFragment1.setArguments(args);
		FragmentTransaction transaction1 = getActivity().getSupportFragmentManager().beginTransaction();
		transaction1.replace(R.id.menus, newFragment1);                 
		transaction1.commit();               


	}



	@Override
	public void onClick(View v) {


		switch (v.getId()) {
		case R.id.time:

			TimeMasterFragment newFragment1 = new TimeMasterFragment();
			Bundle args = new Bundle();
			args.putInt("Position", position);
			newFragment1.setArguments(args);
			FragmentTransaction transaction1 = getActivity().getSupportFragmentManager().beginTransaction();
			transaction1.replace(R.id.menus, newFragment1);                 
			transaction1.commit();

			time.setImageResource(R.drawable.time_active);               
			material.setImageResource(R.drawable.material);
			expenses.setImageResource(R.drawable.expenses);
			break;
		case R.id.material:
			MaterialMasterFragment newFragment2 = new MaterialMasterFragment();
			Bundle args2 = new Bundle();
			args2.putInt("Position", position);
			newFragment2.setArguments(args2);
			FragmentTransaction transaction2 = getActivity().getSupportFragmentManager().beginTransaction();
			transaction2.replace(R.id.menus, newFragment2);                 
			transaction2.commit();

			time.setImageResource(R.drawable.time);               
			material.setImageResource(R.drawable.material_active);
			expenses.setImageResource(R.drawable.expenses);
			//getMaterial(strId);
			break;
		case R.id.expenses:
			ExpensesMasterFragment newFragment3 = new ExpensesMasterFragment();
			Bundle args3 = new Bundle();
			args3.putInt("Position", position);
			newFragment3.setArguments(args3);
			FragmentTransaction transaction3 = getActivity().getSupportFragmentManager().beginTransaction();
			transaction3.replace(R.id.menus, newFragment3);                 
			transaction3.commit();

			time.setImageResource(R.drawable.time);               
			material.setImageResource(R.drawable.material);
			expenses.setImageResource(R.drawable.expenses_active);

			break;




		default:
			break;
		}



	}
}
